package com.jhoncy.rapid.base.controller;

import com.jhoncy.rapid.base.bo.BasePermissionTypeEnum;
import com.jhoncy.rapid.base.pojo.BasePermission;
import com.jhoncy.rapid.base.repository.BasePermissionRepository;
import com.jhoncy.rapid.base.service.BasePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhuangqi
 * @date 2017/7/21.
 */
@RestController
@RequestMapping(value = "/permission")
public class BasePermissionController {

    @Autowired
    private BasePermissionService basePermissionService;



    @GetMapping(value = "/auths/{userId}")
    public ResponseEntity<List<BasePermission>> findBasePermissionsByUserId(@PathVariable String userId) {
        List<BasePermission> permissions = basePermissionService.
                listByUserIdAndType(userId, BasePermissionTypeEnum.AUTH.name());
        return ResponseEntity.ok(permissions);
    }

    @GetMapping(value = "/menus")
    public ResponseEntity<List<BasePermission>> findMenus() {
        List<BasePermission> menus = basePermissionService.listMenus();
        return ResponseEntity.ok(menus);
    }
}
